using Game.Main.Model;
using SimpleJSON;

namespace Game.Component
{
	public class CatMachineBoxItem : BaseItem
	{
		public enum State
		{
			Close = 0,
			Open = 1
		}

		public State state;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
			SetState((State)data.state);
		}

		public void SetState(State val)
		{
			state = val;
			if (state == State.Close)
			{
				SetPlatformColliderEnable(false);
				SetChildsColliderEnabled(false);
			}
			else
			{
				SetPlatformColliderEnable(true);
				SetChildsColliderEnabled(true);
			}
		}

		public override bool AttachItem(BaseItem item, DepthType depthType, AttachType attachType, bool updatePosition)
		{
			if (state == State.Close)
			{
				item.SetAllCollidersEnabled(false);
			}
			return base.AttachItem(item, depthType, attachType, updatePosition);
		}

		public override void PackData(JSONObject obj)
		{
			base.PackData(obj);
			obj["33"] = (int)state;
		}
	}
}
